Repository navigation
mcpx: structured upstream-error carriage on the ask path + local-error origin marker (#2435) - #9038
Conversation
…l-error origin marker (#2435)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 29 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bad7d6aea2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if resp != nil && resp.Error != nil && !resp.Error.relayed { | ||
| // An error mcpx minted itself, anywhere in the dispatch | ||
| // below: stamp its local origin (#2435). A relayed peer | ||
| // error keeps the peer's data exactly as it arrived. | ||
| resp.Error = withLocalOrigin(resp.Error) |
There was a problem hiding this comment.
Preserve relay provenance through task execution
When an upstream error passes through task execution, startTask copies only code, message and data into tasks.Fault (tasks.go:109–112). Both the eager completion path (tasks.go:367–369) and legacy tasks/result (tasks.go:698–700) reconstruct an rpcError without relayed, so this new check stamps a peer's error as local and modifies its data. Preserve the provenance through fault storage and reconstruction so task-backed upstream failures remain unchanged, just like direct failures.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 16959a3 (queue task 8625, lane code-d).
tasks.Fault now carries the provenance end to end: a new Relayed field (persisted in the fault JSON, so it survives the store and its database round-trip) is set at both fault mint sites — startTask's closure copies err.relayed, and driveAsked copies resp.Error.relayed — and both reconstruction sites (the eager completion path and legacy tasks/result) rebuild the rpcError with relayed: fault.Relayed, so HandleOn leaves a task-backed peer error byte-identical and unmarked, exactly like the direct path.
Failing-first tests (they reproduced this finding before the fix): TestARelayedPeerErrorThroughAnEagerTaskKeepsItsData, TestARelayedPeerErrorThroughTasksResultKeepsItsData, TestARelayedPeerErrorThroughAnAskedTaskKeepsItsData — each asserts the upstream's code/message/data arrive unchanged with no mcpx marker. Full internal/mcpserver, internal/tasks and internal/cli suites pass on the laptop.
| writeJSON(w, http.StatusBadRequest, response{JSONRPC: "2.0", | ||
| Error: &rpcError{Code: codeParse, Message: err.Error()}}) | ||
| Error: withLocalOrigin(&rpcError{Code: codeParse, Message: err.Error()})}) |
There was a problem hiding this comment.
Mark the remaining transport-local error responses
For an HTTP POST containing [], the adjacent empty-batch branch still returns an unmarked local error. Other pre-dispatch responses also bypass HandleOn, including rejected Origins (server.go:2064), DELETE session failures (server.go:2302–2308) and batchRefused (transport.go:125–128). Consequently, clients cannot consistently use the new marker to distinguish mcpx refusals from upstream errors. Stamp these remaining transport responses and add a table-driven guard covering the error families rather than only the two dispatch cases in the new tests.
AGENTS.md reference: pkgs/mcpx/internal/AGENTS.md:L11-L12
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 16959a3 (queue task 8625, lane code-d).
The remaining pre-dispatch responses are now stamped withLocalOrigin at their mint sites, so no caller can bypass the stamp: batchRefused itself (covers the HTTP modern/legacy refusals and the stdio batch path), the three runBatch element-framing errors (unparseable element, initialize-in-batch, per-request-metadata element), serveBatch's empty-batch and unknown-session errors, ServeHTTP's rejected-Origin response, both serveDELETE errors, and the serveGET family (the notAllowed closure, unknown session, and the second-stream conflict).
Class guard, per the repo's AGENTS.md rule for a class of bug: TestTransportLocalErrorsCarryTheLocalOriginMarker is table-driven over eleven transport-local error families and fails if any one of them ships unmarked. It reproduced this finding on every case before the fix and passes after it; full internal/mcpserver suite green on the laptop.
…ocal errors (#2435) Codex review on PR #9038, two P2 findings: (1) task execution flattened a relayed peer error into a plain fault, so the eager and tasks/result reconstructions were stamped with the local-origin marker and the peer data mutated - tasks.Fault now carries Relayed (persisted in fault JSON) from both fault mint sites (startTask, driveAsked) to both reconstruction sites. (2) Pre-dispatch transport errors bypassed HandleOn and went unmarked - batchRefused, runBatch element framing, serveBatch empty/unknown-session, ServeHTTP rejected Origin, serveDELETE and serveGET refusals now stamp withLocalOrigin at the mint. Failing-first tests: relayed data byte-identical through eager, tasks/result and asked tasks; table guard over eleven transport-local error families.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16959a3853
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case map[string]any: | ||
| if inner, ok := d["mcpx"].(map[string]any); ok { | ||
| inner["origin"] = "local" |
There was a problem hiding this comment.
Copy error data before adding the origin marker
When two clients concurrently retrieve tasks/result for the same locally failed task, this mutates a shared map without synchronization. runInner already calls HandleOn, so the stored fault contains the marker map; Store.Result returns that same fault, and each tasks/result response reuses fault.Data before calling this function again. Consequently, concurrent retrievals write inner["origin"] simultaneously, potentially causing a fatal concurrent-map-write error or racing with response serialization. Copy both the outer data map and the nested mcpx map before modifying them.
Useful? React with 👍 / 👎.
|
agent-note:v1 |
What
The #2435 Phase 1 remainder (the daemon /v1 structured carriage and the direct gateway relay already landed):
(a) Ask path relays the structured upstream error verbatim.
daemonAsker.PollbuiltOutcome.Upstreamfrom the text heuristic (upstreamError, string-matching the rendered error) even though the reply's structuredupstreamfield was in hand — losingdataentirely (the heuristic recovers only code + message). Poll now prefersreply.Upstreamverbatim (code, message, data) and keeps the heuristic as the fallback for replies without the field. The -32021 classification already read the structured field; now the relayed error matches it.(b) Local-error origin marker. Every error mcpx mints itself on the MCP surface now carries
"mcpx": {"origin": "local"}merged into itsdata. Implementation:rpcErrorgains an unexportedrelayedflag set only byUpstreamError.relay;HandleOnstamps the marker viawithLocalOriginon every non-relayed error response — one minting point covering name checks (-32602), internal failures (-32603), policy refusals, and the rest of the dispatch surface — plus direct stamps on the pre-dispatch framing errors (HTTP/stdio parse, invalid-request, header and session checks) that bypassHandleOn. Peer errors are relayed byte-identical and never marked. Data that is not a JSON object has nowhere to merge a key and is left as-is (every current local mint carries nil or object data).Cross-repo check (per the packet): dezren39/nix vendors no copy of these files (GitHub code search for the package in that repo: 0 hits; it consumes mcpx from this repo), so there is nothing to port.
Tests
internal/cli:TestAskPollPrefersTheStructuredUpstreamError(verbatim code/message/data over a differing text rendering),TestAskPollMissingCapabilityKeepsItsData(-32021 keeps requiredCapabilities in both the classified error and the relayed upstream),TestAskPollFallsBackToTheTextHeuristic(no-field replies unchanged, no invented data).internal/mcpserver:TestALocallyMintedErrorCarriesTheLocalOriginMarker(marker merged into notFound's existing{uri}data),TestALocallyMintedErrorWithoutDataIsMarkedToo,TestARelayedPeerErrorIsNeverMarkedLocal(relayed -32602 with peer data arrives byte-identical, unmarked) — the ask-path/gateway parity the issue asks for is asserted from both sides: same error shape, origin marker the only difference, and it appears only on mcpx's own.internal/mcpserverandinternal/clisuites pass locally;gofmtclean. (The pre-existing main-baseline failures ininternal/settings/internal/e2e— mcpx baseline: four tests red on main (settings docs/scriptenv + e2e envguard classification) #9017 — are untouched by this change and will show on CI as they do for every mcpx PR.)Closes #2435.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.